package darknet.application.chat.impl.net.message;

import darknet.core.impl.net.AbstractMessage;
import darknet.core.spec.net.MessageHeader;
import darknet.core.spec.net.Node;

/**
 * Broadcast version of a join channel message.
 *
 * This message is used by a channel owner to notify connected nodes a new
 * node has joined the channel.
 * 
 * @author yoyo
 */
public class BroadcastJoinChannelMessage extends AbstractMessage {

    // TODO use a decorator for broadcasted message.

    /** Channel name */
    private String channelName = null;

    /** Joiner node */
    private Node joiner = null;

    /**
     * Initialize a new broadcast channel message
     * 
     * @param header
     * @param from
     * @param to
     * @param channelName
     * @param joiner
     */
    public BroadcastJoinChannelMessage(MessageHeader header, Node from, Node to,
            String channelName, Node joiner) {

        super(header, from, to);

        if (channelName == null || channelName.length() == 0) {
            throw new IllegalArgumentException("channelName is invalid");
        }
        this.channelName = channelName;

        if (joiner == null) {
            throw new IllegalArgumentException("joiner is invalid (null)");
        }
        this.joiner = joiner;
    }

    /**
     * Get the channel name.
     * 
     * @return
     */
    public String getChannelName() {
        return channelName;
    }

    /**
     * Get the joiner.
     * 
     * @return
     */
    public Node getJoiner() {
        return joiner;
    }
}
